<?php
/*
	排队
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	//顾客管理
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['store_id']=$store_id;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_qiuyuyue_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as $v){
		$v['screenurl']=custom_url('jy_qiuyuyue/queue_screen//store_id='.$store_id,true);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'顾客列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'name','title'=>'顾客名称','type'=>'string'),
			array('name'=>'mobile','title'=>'顾客手机','type'=>'string'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'isblack'),
		),
		),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('queue',array('id'=>$id));

	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['htmls']=array(
			'type' => 'edit',
			'post' => 'post',
			'tabs'=>array(
				array('op'=>'queue','title'=>'顾客列表'),
				array('op'=>'edit','title'=>'新建顾客'),
				array('op'=>'setting','title'=>'大屏幕设置'),
			),
			'edits' => array(
				array('title'=>'顾客设置','list'=>array(
				array('name'=>'title','title'=>'顾客名称','type'=>'string','help'=>'1-2桌,3-4桌,5-6桌,7-10桌'),
				array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
				array('name'=>'num','title'=>'提前通知人数','type'=>'string','help'=>'例如：提前5人发信息通知！'),
				array('name'=>'pre','title'=>'顾客编号前缀','type'=>'string','help'=>'例如：A-,B-,C-'),
				array('name'=>'display','title'=>'排序','type'=>'string','help'=>'数字越大排名越靠前！'),
             ),),),
     );
	$return['status']=array(
		'0'=>'启用',
		'1'=>'关闭',
	);
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array('status','title','store_id','pre','display','num'),$post);

	$id=intval($post['id']);
	if($id){
		$this->update('queue',$data,array('id'=>$id));
		exi('修改顾客成功！','','queue');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['store_id']=$store_id;
		$this->insert('queue',$data);
		exi('新增顾客成功！','','queue');
	}
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_qiuyuyue_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='isblack'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['isblack'])){
		$update['isblack']=intval($post['isblack']);
	}
	if($update){
		pdo_update('jy_qiuyuyue_member',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}